package mt;

import java.util.Scanner;

/**
 * @author zhangmin
 * @create 2022-03-26 15:48
 */
public class meituan_0326_2 {
    public static void main(String[] args) {
        Scanner cin=new Scanner(System.in);
        int n=cin.nextInt();
        int[] nums=new int[n];

        for (int i = 0; i < n; i++) {
            nums[i]= cin.nextInt();
        }
        long target=(nums[0]+nums[n-1])/2;
        //这个才是左右边界
        int left=0,rigth=n-1;
        while (left<=rigth){
            int mid=left+(left-rigth)/2;
            if (nums[mid]<target){
                left=left+1;
            }else if (nums[mid]==target){
                System.out.println(Math.min(nums[mid]-nums[left],nums[rigth]-nums[mid]));
                return;
            }else {
                rigth=mid-1;
            }
        }
        //最终结果可能是left，也可能是right，所以需要判断四个距离里面的最小值
        int res=Math.min(nums[left]-nums[0],Math.min(nums[n-1]-nums[rigth],Math.min(nums[rigth]-nums[0],nums[n-1]-nums[left])))+1;
        System.out.println(res);
    }
}
